# -*- coding: utf-8 -*-
from Page.bankPage import bankPage
import time
import re
from xlutils.copy import copy
import win32gui
import win32con
import os
import xlwt
import xlrd

class bank():
    def __init__(self,driver):
        self.driver=driver
        self.bankPage=bankPage(self.driver)
    def History_Subsidiary(self):
        handle1 = self.driver.current_window_handle
        print('登录后' + handle1)
        # 点击银行账户
        self.bankPage.btnBankAcc().click()
        time.sleep(1)
        # 点击历史明细
        self.bankPage.btnHistory().click()
        time.sleep(1)
        # 打印当前frame
        print(self.driver.find_elements_by_tag_name("iframe"))

        i=0
        while(i<2):
            i=i+1
            self.driver.switch_to.default_content()
            self.driver.switch_to.frame("tabs-iframe-name-webgen-2")
            time.sleep(1)
            self.bankPage.btnImport().click()
            time.sleep(1)
            print('1111111111111111111111111111111')
            print(self.driver.find_elements_by_tag_name("iframe"))
            # frame=self.driver.find_elements_by_xpath('//*[@id="transactiondetailupload-iframe"]/iframe')
            self.driver.switch_to.frame("transactiondetailupload-iframe")
            time.sleep(2)
            self.bankPage.btnSWUpload().click()
            time.sleep(1)
            # 上传文件
            os.system(r'C:\Users\tanjm.ext\PycharmProjects\GroupL\TestData\upload.exe')
            time.sleep(3)
            print(self.bankPage.btnUpload())
            self.bankPage.btnUpload().click()
            time.sleep(1)
            m=self.driver.find_element_by_id('f-message-webgen-0-content').text
            print(m)
            n=re.findall(r'[[](.*?)[]]',m)
            print(n)
            excelpath = r'C:/Users/tanjm.ext/PycharmProjects/GroupL/TestData/paymentupdate.xls'
            wtbook = xlrd.open_workbook(excelpath)
            newb=copy(wtbook)
            # sheet = newb.add_sheet('Sheet3')
            sheet=newb.get_sheet(0)
            sheet.write(1,2,float(n[1]))
            newb.save(excelpath)
            time.sleep(1)
            self.driver.find_element_by_id('f-message-webgen-0-okBnt').click()
            time.sleep(1)







